﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Controls
{
    public partial class BoxUserManagerViewAll : System.Web.UI.UserControl
    {

        DateTime datenow = DateTime.Now;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string iduser = Session["Employee_ID"].ToString();
                rpt_viewall.DataSource = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereIDOrderBySort("tbl_SanGiaoDich", "Employee_ID", iduser.ToString(), "SanGiaoDich_Date", "desc");
                rpt_viewall.DataBind();
            }
        }

        protected void rpt_viewall_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                // delete
                int id = Convert.ToInt32(e.CommandArgument.ToString());

                DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_TienIch", "SanGiaoDich_ID", id.ToString());
                
                DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_SanGiaoDich", "SanGiaoDich_ID", id.ToString());
                Response.Redirect("/quanlytaikhoan");
            }
            if (e.CommandName == "update")
            {
                // update
                int id = Convert.ToInt32(e.CommandArgument.ToString());
                DAL.DCollector.DBCollector.Instance.UpdateWhereID("tbl_SanGiaoDich", "SanGiaoDich_Date", datenow.ToString(), "SanGiaoDich_ID", id.ToString());
                Response.Redirect("/quanlytaikhoan");
            }
        }
    }
}